-- SettingMenu
-- 设置菜单
SettingMenu = class()

function SettingMenu:init()
    self.show = false
    self.buttons = {}
    local backButton = TextButton(15,HEIGHT - 50,LP.Back)
    backButton.font = "Futura-Medium"
    backButton.fontSize = 30
    backButton.clicked = function() self.show = false saveSetting() end
    backButton.backColor = color(255,255,255,0)
    backButton.textColor = color(255,255,255,255)
    backButton.posMode = UIConst.PosMode.Corner
    table.insert(self.buttons,backButton)
    
    local swb = TextButton(WIDTH * 0.25,HEIGHT - 150)
    swb.width = WIDTH * 0.4
    swb.height = WIDTH * 0.05
    swb.font = "Futura-Medium"
    swb.fontSize = 30
    swb.setSizeStr = function()
        if GameSetting.ViewChunkDistance == 6 then
            swb.capital = LP.ViewDistance..LP.Normal
        elseif GameSetting.ViewChunkDistance == 8 then
            swb.capital = LP.ViewDistance..LP.Big
        else
            swb.capital = LP.ViewDistance..LP.Small
        end
    end
    swb.setSizeStr()
    swb.clicked = function()
        if GameSetting.ViewChunkDistance == 6 then
            GameSetting.ViewChunkDistance = 8
        elseif GameSetting.ViewChunkDistance == 8 then
            GameSetting.ViewChunkDistance = 4
        else
            GameSetting.ViewChunkDistance = 6
        end
        swb.setSizeStr()
    end
    swb.backColor = color(255,255,255,40)
    swb.pressedBackColor = color(255,255,255,40)
    swb.textColor = color(255,255,255,255)
    table.insert(self.buttons,swb)
    
    local gsb = TextButton(WIDTH * 0.75,HEIGHT - 150)
    gsb.setCapital = function()
        if GameSetting.FancyGraphic then
            gsb.capital = LP.GraphicQuality..LP.HighQuality
        else
            gsb.capital = LP.GraphicQuality..LP.LowQuality
        end
    end
    gsb.setCapital()
    gsb.width = WIDTH * 0.4
    gsb.height = WIDTH * 0.05
    gsb.font = "Futura-Medium"
    gsb.fontSize = 30
    gsb.clicked = function()
        if GameSetting.FancyGraphic then
            GameSetting.EnableParticle = false
        else
            GameSetting.EnableParticle = true
        end
        GameSetting.FancyGraphic = not GameSetting.FancyGraphic
        gsb.setCapital()
    end
    gsb.backColor = color(255,255,255,40)
    gsb.pressedBackColor = color(255,255,255,40)
    gsb.textColor = color(255,255,255,255)
    table.insert(self.buttons,gsb)
    
    local ebb = TextButton(WIDTH * 0.25,HEIGHT - 230)
    ebb.setCapital = function()
        if GameSetting.ShowBob then
            ebb.capital = LP.ShowBob..LP.Enabled
        else
            ebb.capital = LP.ShowBob..LP.Disabled
        end
    end
    ebb.setCapital()
    ebb.width = WIDTH * 0.4
    ebb.height = WIDTH * 0.05
    ebb.font = "Futura-Medium"
    ebb.fontSize = 30
    ebb.clicked = function()
        GameSetting.ShowBob = not GameSetting.ShowBob
        ebb.setCapital()
    end
    ebb.backColor = color(255,255,255,40)
    ebb.pressedBackColor = color(255,255,255,40)
    ebb.textColor = color(255,255,255,255)
    table.insert(self.buttons,ebb)   
    
    local plb = TextButton(WIDTH * 0.25,HEIGHT - 310)
    plb.setCapital = function()
        if GameSetting.PreLoadChunk then
            plb.capital = LP.PreLoadChunk..LP.Enabled
        else
            plb.capital = LP.PreLoadChunk..LP.Disabled
        end
    end
    plb.setCapital()
    plb.width = WIDTH * 0.4
    plb.height = WIDTH * 0.05
    plb.font = "Futura-Medium"
    plb.fontSize = 30
    plb.clicked = function()
        GameSetting.PreLoadChunk = not GameSetting.PreLoadChunk
        plb.setCapital()
    end
    plb.backColor = color(255,255,255,40)
    plb.pressedBackColor = color(255,255,255,40)
    plb.textColor = color(255,255,255,255)
    table.insert(self.buttons,plb)
    
    local hgi = TextButton(WIDTH * 0.75,HEIGHT - 310)
    hgi.setCapital = function()
        if GameSetting.HideGui then
            hgi.capital = LP.HideGui..LP.Enabled
        else
            hgi.capital = LP.HideGui..LP.Disabled
        end
    end
    hgi.setCapital()
    hgi.width = WIDTH * 0.4
    hgi.height = WIDTH * 0.05
    hgi.font = "Futura-Medium"
    hgi.fontSize = 30
    hgi.clicked = function()
        GameSetting.HideGui = not GameSetting.HideGui
        hgi.setCapital()
    end
    hgi.backColor = color(255,255,255,40)
    hgi.pressedBackColor = color(255,255,255,40)
    hgi.textColor = color(255,255,255,255)
    table.insert(self.buttons,hgi)
    
    local slb = TextButton(WIDTH * 0.25,HEIGHT - 390)
    slb.setCapital = function()
        if GameSetting.SmoothLight >= 0.6 then
            slb.capital = LP.SmoothLight..LP.High
        elseif GameSetting.SmoothLight < 0.3 then
            slb.capital = LP.SmoothLight..LP.Disabled
        else
            slb.capital = LP.SmoothLight..LP.Low
        end
    end
    slb.setCapital()
    slb.width = WIDTH * 0.4
    slb.height = WIDTH * 0.05
    slb.font = "Futura-Medium"
    slb.fontSize = 30
    slb.clicked = function()
        Block.getBrightnessAtCoord = Block.getBrightnessAtCoordA
        Block.getBrightnessAtCoordC = Block.getBrightnessAtCoordCA
        if GameSetting.SmoothLight >= 0.6 then
            GameSetting.SmoothLight = 0
            Block.getBrightnessAtCoord = Block.getBrightnessAtCoordB
            Block.getBrightnessAtCoordC = Block.getBrightnessAtCoordCB
        elseif GameSetting.SmoothLight < 0.3 then
            GameSetting.SmoothLight = 0.4
        else
            GameSetting.SmoothLight = 0.9
        end
        slb.setCapital()
    end
    slb.backColor = color(255,255,255,40)
    slb.pressedBackColor = color(255,255,255,40)
    slb.textColor = color(255,255,255,255)
    table.insert(self.buttons,slb)
    
    local sldb = TextButton(WIDTH * 0.75,HEIGHT - 390)
    sldb.setCapital = function()
        if GameSetting.DarkEx <= 1.5 then
            sldb.capital = LP.DarkEx..LP.Low
        else
            sldb.capital = LP.DarkEx..LP.High
        end
    end
    sldb.setCapital()
    sldb.width = WIDTH * 0.4
    sldb.height = WIDTH * 0.05
    sldb.font = "Futura-Medium"
    sldb.fontSize = 30
    sldb.clicked = function()
        GameSetting.DarkEx = 3 - GameSetting.DarkEx
        sldb.setCapital()
    end
    sldb.backColor = color(255,255,255,40)
    sldb.pressedBackColor = color(255,255,255,40)
    sldb.textColor = color(255,255,255,255)
    table.insert(self.buttons,sldb)
    
    local bb = TextButton(WIDTH * 0.25,HEIGHT - 470)
    bb.setCapital = function()
        if GameSetting.Brightness >= 0.5 then
            bb.capital = LP.Brightness..LP.High
        elseif GameSetting.Brightness < 0.25 then
            bb.capital = LP.Brightness..LP.Low
        else
            bb.capital = LP.Brightness..LP.Medium
        end
    end
    bb.setCapital()
    bb.width = WIDTH * 0.4
    bb.height = WIDTH * 0.05
    bb.font = "Futura-Medium"
    bb.fontSize = 30
    bb.clicked = function()
        if GameSetting.Brightness >= 0.5 then
            GameSetting.Brightness = 0
        elseif GameSetting.Brightness < 0.25 then
            GameSetting.Brightness = 0.25
        else
            GameSetting.Brightness = 0.5
        end
        bb.setCapital()
    end
    bb.backColor = color(255,255,255,40)
    bb.pressedBackColor = color(255,255,255,40)
    bb.textColor = color(255,255,255,255)
    table.insert(self.buttons,bb)
    
    local tpw = TextButton(WIDTH * 0.75,HEIGHT - 230)
    tpw.setCapital = function()
        if GameSetting.ThirdPersonView then
            tpw.capital = LP.ThirdPersonView..LP.Enabled
        else
            tpw.capital = LP.ThirdPersonView..LP.Disabled
        end
    end
    tpw.setCapital()
    tpw.width = WIDTH * 0.4
    tpw.height = WIDTH * 0.05
    tpw.font = "Futura-Medium"
    tpw.fontSize = 30
    tpw.clicked = function()
        GameSetting.ThirdPersonView = not GameSetting.ThirdPersonView
        tpw.setCapital()
    end
    tpw.backColor = color(255,255,255,40)
    tpw.pressedBackColor = color(255,255,255,40)
    tpw.textColor = color(255,255,255,255)
    table.insert(self.buttons,tpw)
    
    --[[self.sw = Switch(400,300)
    self.sw.frameColor = color(255, 255, 255, 75)
    self.sw.buttonColor = color(255, 255, 255, 200)
    self.sw.offBackColor = color(0, 0, 0, 60)
    self.sw.onBackColor = color(255, 255, 255, 100)]]
end

function SettingMenu:draw()
    fill(255, 255, 255, 100)
    rectMode(CORNER)
    strokeWidth(0)
    rect(0,HEIGHT - 70,WIDTH,HEIGHT)
    fill(255, 255, 255, 255)
    font("Futura-Medium")
    fontSize(40)
    text(LP.Setting,WIDTH / 2,HEIGHT - 35)
    for _,v in pairs(self.buttons) do
        v:draw()
    end
end

function SettingMenu:touched(touch)
    for _,v in pairs(self.buttons) do
        v:touched(touch)
    end
end
